﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace The_LarX
{
    public class DownMessage : GuideLikeComponent
    {
        public int TimeToStay;
        public string Message;

        public DownMessage(string message, int TimeToStay)
        {
            this.Message = message;
            this.TimeToStay = TimeToStay;

            this.NeedToBlockUpdate = false;
        }

        public void RestartTimer()
        {
            Timer = 0;
            Closing = false;
        }

        public event EventHandler Finished;

        private int Timer;
        private int Alpha;
        private bool Closing;
        public override void Update()
        {
            base.Update();

            if (!Closing)
            {
                if (Alpha < 255)
                {
                    Alpha += 5;
                }
                else
                {
                    Alpha = 255;
                    Timer += Engine.GameTime.ElapsedGameTime.Milliseconds;
                    if (Timer > TimeToStay)
                    {
                        Closing = true;
                    }
                }
            }
            else
            {
                if (Alpha > 0)
                {
                    Alpha -= 5;
                }
                else
                {
                    Alpha = 0;
                    this.Disable();
                    if (Finished != null)
                        Finished(this, EventArgs.Empty);
                }
            }
        }

        public override void Draw()
        {
            base.Draw();

            int height = Engine.GraphicsDevice.PresentationParameters.BackBufferHeight;
            Vector2 textSize = Engine.FontManager.GetFont("Kootenay").MeasureString(Message);
            Engine.RenderManager.DrawString(Message, 2, Alpha, new Vector2(Engine.RenderManager.CenterTextX(Message,
                        "Kootenay", 1), height - textSize.Y - 30), "Kootenay", new Color(255, 255, 255, Alpha), null);
        }
    }
}
